﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Patent.CN;
using DevExpress.XtraCharts;

public partial class China_Chart_ChineseTypeChart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                //int topicID =  Int32.Parse(Session["ID"].ToString());
                int topicID = Convert.ToInt32(Session["topicID"].ToString());
                ChinaAnalysis cnAnalysis = new ChinaAnalysis(topicID);

                if (cnAnalysis.IsChineseTopic())
                {

                    WebChartCN.Enabled = true;
                    WebChartCN.Visible = true;


                    int syxx = cnAnalysis.GetCount("syxx");
                    int wgsj = cnAnalysis.GetCount("wgzl");
                    int fmzl = cnAnalysis.GetCount("fmzl");
                    int sum = cnAnalysis.GetAllPatentsCount();

                    DataTable dt = new DataTable("dd");
                    dt.Columns.Add(new DataColumn("Name", typeof(string)));
                    dt.Columns.Add(new DataColumn("Value", typeof(int)));
                    dt.Columns.Add(new DataColumn("Percent", typeof(string)));
                    DataRow dtRowFmzl = dt.NewRow();
                    dtRowFmzl["Name"] = "发明专利";
                    dtRowFmzl["Value"] = fmzl;
                    dtRowFmzl["Percent"] = (float)fmzl / sum * 100 + "%";
                    DataRow dtRowSyxx = dt.NewRow();
                    dtRowSyxx["Name"] = "实用新型";
                    dtRowSyxx["Value"] = syxx;
                    dtRowSyxx["Percent"] = (float)syxx / sum * 100 + "%";
                    DataRow dtRowWgsj = dt.NewRow();
                    dtRowWgsj["Name"] = "外观设计";
                    dtRowWgsj["Value"] = wgsj;
                    dtRowWgsj["Percent"] = (float)wgsj / sum * 100 + "%";

                    dt.Rows.Add(dtRowFmzl);
                    dt.Rows.Add(dtRowSyxx);
                    dt.Rows.Add(dtRowWgsj);

                    dt.AcceptChanges();
                    Series series1 = new Series("Pie Series 1", ViewType.Pie);
                    WebChartCN.Series.Add(series1);
                    series1.ArgumentScaleType = ScaleType.Qualitative;
                    series1.ValueScaleType = ScaleType.Numerical;
                    series1.DataSource = dt;
                    series1.ArgumentDataMember = "Name";
                    series1.ValueDataMembers.AddRange(new string[] { "Value" });
                    series1.SeriesPointsSorting = SortingMode.Ascending;
                    series1.SeriesPointsSortingKey = SeriesPointKey.Value_1;
                    ((PieSeriesView)series1.View).Rotation = 90;
                    ((PieSeriesLabel)series1.Label).Position = PieSeriesLabelPosition.TwoColumns;
                    ((PiePointOptions)series1.PointOptions).PointView = PointView.ArgumentAndValues;
                    series1.PointOptions.ValueNumericOptions.Format = NumericFormat.Percent;
                }
                else
                {
                    WebChartCN.Enabled = false;
                    WebChartCN.Visible = false;

                }
            }
            catch (System.FormatException)
            {
            }
            catch (System.Exception)
            {
                WebChartCN.Visible = false;
            }
        }
        // Prevent IE Cache
        Response.Expires = 0;
    }
}
